export default {
  name: 'OrderDetail',
  props: {
    visible: {
      type: Boolean,
      default: false
    },
    orderId: {
      type: [String, Number],
      default: ''
    }
  },
  data() {
    return {
      orderInfo: {
        orderNo: '',
        createTime: '',
        status: '',
        deceasedName: '',
        deceasedGender: '',
        deceasedAge: '',
        serviceAddress: '',
        contactPhone: '',
        items: [],
        totalAmount: 0,
        discount: 0,
        remark: '',
        activities: []
      }
    }
  },
  methods: {
    // 获取订单详情
    async getOrderDetail() {
      try {
        // 这里调用获取订单详情接口
        // const res = await this.$api.order.getDetail(this.orderId)
        // this.orderInfo = res.data

        // 模拟数据
        this.orderInfo = {
          orderNo: 'DD20240101001',
          createTime: '2024-01-01 12:00:00',
          status: 'pending',
          deceasedName: '张三',
          deceasedGender: '男',
          deceasedAge: 75,
          serviceAddress: '北京市朝阳区xx街道xx号',
          contactPhone: '13800138000',
          items: [
            {
              name: '豪华骨灰盒',
              category: '寿盒',
              price: 3999,
              quantity: 1
            },
            {
              name: '寿衣套装',
              category: '寿衣',
              price: 2999,
              quantity: 1
            }
          ],
          totalAmount: 6998,
          discount: 500,
          remark: '请准时送达',
          activities: [
            {
              time: '2024-01-01 12:00:00',
              type: 'primary',
              content: '创建订单'
            },
            {
              time: '2024-01-01 12:05:00',
              type: 'success',
              content: '支付完成'
            }
          ]
        }
      } catch (error) {
        this.$message.error('获取订单详情失败')
      }
    },

    // 获取订单状态类型
    getOrderStatusType(status) {
      const statusMap = {
        pending: 'warning',
        confirmed: 'success',
        completed: 'success',
        cancelled: 'info'
      }
      return statusMap[status] || 'info'
    },

    // 获取订单状态文本
    getOrderStatusText(status) {
      const statusMap = {
        pending: '待确认',
        confirmed: '已确认',
        completed: '已完成',
        cancelled: '已取消'
      }
      return statusMap[status] || '未知状态'
    },

    // 确认订单
    async handleConfirm() {
      try {
        await this.$confirm('确认接受该订单?', '提示', {
          type: 'warning'
        })
        // 调用确认订单接口
        // await this.$api.order.confirm(this.orderId)
        this.$message.success('订单确认成功')
        this.$emit('refresh')
        this.handleClose()
      } catch (error) {
        if (error !== 'cancel') {
          this.$message.error('订单确认失败')
        }
      }
    },

    // 关闭弹窗
    handleClose() {
      this.$emit('update:visible', false)
    }
  }
}